import Page
from Page import Launcher
from Base.Base import Base
from selenium.webdriver.common.by import By


class LauncherPasswordPage(Base):
    """
    桌面输入密码页面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 数字列表按钮
        self.password_list_number_btn = (By.XPATH, Launcher.password_list_number_btn.format(1))

        # 登录按钮
        self.password_login_btn = (By.XPATH, Launcher.RESOURCE_ID.format("password_confirm_bt"))

    def click_number(self, number=1):
        """
        根据number的值点击数字

        :param number: 默认取1, 取值范围[0,9]
        :return:
        """
        self.password_list_number_btn = (By.XPATH, Launcher.password_list_number_btn.format(number))
        self.click_element(self.password_list_number_btn)

    def click_login(self):
        """
        点击登录

        :return:
        """
        self.click_element(self.password_login_btn)

    def login(self, number=1):
        """
        业务方法: 输入密码, 默认输入4个1

        :param number:
        :return:
        """
        for i in range(4):
            self.click_number(number)
        self.click_login()
